using Commons.Models.Locks;
using Commons.Models.Settings.Dtos.Locks;
using System;
using System.Collections.Generic;

namespace Commons.Models.Settings.Mappers.Locks
{
	public class UnlockConditionsMapper
	{
		protected static Dictionary<Type, IMapper<IUnlockConditionDto, UnlockCondition>> mappers;

		static UnlockConditionsMapper()
		{
			mappers = new Dictionary<Type, IMapper<IUnlockConditionDto, UnlockCondition>>();
			mappers.Add(typeof(UserStatsUnlockConditionDto), new UserStatsUnlockConditionMapper());
		}

		protected UnlockCondition CreateUnlockCondition(IUnlockConditionDto unlockConditionDto)
		{
			IMapper<IUnlockConditionDto, UnlockCondition> mapper;
			if (!mappers.TryGetValue(unlockConditionDto.GetType(), out mapper))
			{
				throw new ArgumentException("Cannot find mapper registered in UnlockConditionsMapper class for type: "+unlockConditionDto.GetType());
			}

			return mapper.Map(unlockConditionDto);
		}
	}
}

